﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Common.Core
{
	public static class Extensions
	{
		public static AttributeType GetAttribute<AttributeType>( this ICustomAttributeProvider target ) where AttributeType : Attribute
		{
			AttributeType[] attributes = target.GetCustomAttributes( typeof(AttributeType), true ) as AttributeType[];
			AttributeType result = attributes != null && attributes.Length > 0 ? attributes[0] : null;
			return result;
		}

		public static AttributeType[] GetAttributes<AttributeType>( this ICustomAttributeProvider target ) where AttributeType : Attribute
		{
			AttributeType[] result = target.GetCustomAttributes( typeof(AttributeType), true ) as AttributeType[];
			return result ?? new AttributeType[0];
		}
	}
}
